import Vue from "vue";
import axios from "axios";
import utils from "@/utils/utils";

Vue.prototype.$axios = axios;

// 数据接口API

export function requestApi(config) {
  let baseUrl = utils.setBaseUrl();
  // 创建实例
  const api = axios.create({
    baseURL: baseUrl + "api",
    timeout: 5000,
  });

  api.interceptors.request.use(
    (config) => {
      // console.log(config)
      return config;
    },
    (err) => {
      return Promise.reject(err);
    }
  );
  api.interceptors.response.use(
    (result) => {
      // console.log(result.data)
      return result.data;
    },
    (err) => {
      return Promise.reject(err);
    }
  );

  return api(config);
}
